package com.decent.ejfadmin.configure.dao;

import com.decent.ejfadmin.configure.entity.UserPlatformBanner;
import com.decent.ejfadmin.configure.entity.dto.UserPlatformBannerDTO;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Objects;

/**
 * describe:
 *
 * @author 陈豆豆
 * @date 2019/08/10
 */
public class BannerConfigDaoProvider {
    public String listBanner(HashMap<String, UserPlatformBanner> map) {
        UserPlatformBanner userPlatformBanner = map.get("userPlatformBanner");
        StringBuilder sql = new StringBuilder();
        sql.append("select * from yuhuang_user_platform_banner where 1=1 ");
        if (Objects.nonNull(userPlatformBanner)) {
            if (StringUtils.isNotBlank(userPlatformBanner.getPictureName())) {
                sql.append(" and picture_name=#{userPlatformBanner.pictureName} ");
            }
        }
        sql.append(" order by sort");
        return sql.toString();
    }

    public String updateBanner(HashMap<String, UserPlatformBannerDTO> map) {
        UserPlatformBannerDTO userPlatformBanner = map.get("userPlatformBanner");
        StringBuilder sql = new StringBuilder();
        sql.append("update yuhuang_user_platform_banner set ");
        if (Objects.nonNull(userPlatformBanner)) {
            if (StringUtils.isNotBlank(userPlatformBanner.getPictureName())) {
                sql.append("  picture_name=#{userPlatformBanner.pictureName}, ");
            }
            if (Objects.nonNull(userPlatformBanner.getImageBinary())) {
                sql.append(" image_binary=#{userPlatformBanner.imageBinary}, ");
            }
            if (Objects.nonNull(userPlatformBanner.getSort())) {
                sql.append(" sort=#{userPlatformBanner.sort}, ");
            }
            if (Objects.nonNull(userPlatformBanner.getPictureUrl())) {
                sql.append("  picture_url=#{userPlatformBanner.pictureUrl}, ");
            }
            if (Objects.nonNull(userPlatformBanner.getPictureKey())) {
                sql.append("  picture_key=#{userPlatformBanner.pictureKey}, ");
            }
            if (Objects.nonNull(userPlatformBanner.getRemark())) {
                sql.append("  remark=#{userPlatformBanner.remark}, ");
            }
        }
        sql.append(" gmt_modified=now() where id=#{userPlatformBanner.id} ");
        return sql.toString();
    }

}
